<!--
 * @Author: liaoshuang 345324985@qq.com
 * @Date: 2023-12-22 11:18:56
 * @LastEditors: liaoshuang 345324985@qq.com
 * @LastEditTime: 2024-04-01 16:55:05
 * @FilePath: \h5-pad-vue2\src\views\home\index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="home">
    <div class="center" v-for="item in list" :key="item.homeId">
      <div class="title">
        <div class="name">{{ item.title }}</div>
        <div class="des">
          <span>{{ item.year }}</span>
          <span>{{ departmentName }}</span>
          <span>{{ currentFacility }}</span>
        </div>
      </div>
      <div class="btns KPI">
        <div
          class="item"
          v-for="(value, key) in item.parameters"
          :key="value"
          v-if="btns.includes(key)"
        >
          <div class="img"></div>
          <div
            plain
            type="info"
            v-if="key === 'MachineStatus'"
            class="myButton"
          >
            <!--  @click="toNextRouter(value, key)" -->
            {{ departmentName }}
          </div>
          <div
            plain
            type="info"
            v-else
            class="myButton"
            @click="toNextRouter(value, key)"
          >
            {{ value }}
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import { Button } from "vant";

export default {
  name: "Login",
  components: { Button },
  data() {
    return {
      currentFacility: "",
      list: [],
      departmentName: JSON.parse(sessionStorage.getItem("currentDepartment"))
        .name,
      btns: [],
    };
  },
  mounted() {
    this.getLang();
    this.getHomeList();
    this.getBtns();
  },
  methods: {
    outEv() {
      sessionStorage.removeItem("token");
      location.reload();
    },
    getLang() {
      this.currentFacility = localStorage.getItem("currentFacility");
    },
    async getHomeList() {
      const res = await axios.post("/SicCore/GetHomes");
      this.list = res.items;
    },
    toNextRouter(v, k) {
      switch (k) {
        case "ForemanBtn":
          this.$router.push({ name: "ShopFloor" });

          break;
          // case "FunctionHead":
          //   // openFunctionHeadModal();
          //   this.$router.push({
          //     path: "/functionHeadData",
          //   });
          //   // setTimeout(() => {
          //   //   window.location.reload();
          //   // }, 100);
          //   break;

          // case "PlantManager":
          //   this.$router.push({ name: "PlantManager" });
          //   break;
          // case "MachineStatus":
          //   openMachineStatusModal();
          //   break;
          // case "SQCDP":
          window.open("http://10.92.20.180:11100");
          break;
        default:
          break;
      }
    },
    async getBtns() {
      const res = await axios.post("/SicCore/GetMenus", {
        maxType: 3,
        userId: JSON.parse(sessionStorage.getItem("userInfo")).userName,
      });
      this.btns = res
        .filter((item) => item.name == "Home")[0]
        .children.map((item) => item.name);
      this.$nextTick(() => {
        document.querySelectorAll(".center").forEach((item, index) => {
          console.log(item);
          if (item.children[1].children.length == 0) {
            item.style.display = "none";
          }
        });
      });
    },
  },
};
</script>
<style scoped lang="less">
.home {
  // position: absolute;
  // top: 0;
  // bottom: 0;
  // left: 0;
  // right: 0;
  // display: flex;
  // align-items: center;
  padding-bottom: 34px;
}
.nav {
  // display: flex;
  width: 100%;

  .navin {
    margin-bottom: 0.2667rem;
    flex: 1;
    height: 80px;
    line-height: 80px;
    font-size: 24px;
    text-align: center;
    border-radius: 10px;
    border: 2px dashed #e8f2fa;
    background-color: #dcebf8;
  }
}
.center {
  position: relative;
  top: 20%;
  padding: 20px;
  box-shadow: rgb(136 165 191 / 48%) 6px 2px 16px 0,
    rgb(255 255 255 / 80%) -6px -2px 16px 0;
  margin-bottom: 10px;
  .title {
    display: flex;
    align-items: center;
    margin-bottom: 20px;
    .name {
      font-size: 18px;
      border-bottom: 4px solid #3ce9e1;
    }
  }
  .btns {
    display: flex;
    flex-wrap: wrap;
    .item {
      box-sizing: border-box;
      margin: 5px 10px;
      width: 44%;
      position: relative;
      display: flex;
      flex-direction: column;
      // background: linear-gradient(to bottom, #093e60 5%, #fff 65%);
      border-radius: 15px;
      border: 1px solid #ccc;
      overflow: hidden;
    }
    .img {
      height: 70px;
      background: url(@/asstes/images/homeItemBg.png) center top no-repeat;
      width: 100%;
      background-size: cover;
    }
    .list {
      position: absolute;
      bottom: 0;
      div {
        max-width: 350px;
        min-width: 150px;
        background-color: black;
        height: 45px;
      }
    }
    .myButton {
      text-align: center;
      font-size: 18px;
    }
  }
  .des {
    display: flex;
    font-size: 15px;
    span {
      padding: 0 10px;
      border-right: 1px solid #898989;
    }
    span:last-child {
      border: 0;
    }
  }
}
.footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  z-index: 999;
}
@media (max-width: 375px) {
  .item {
    width: 80% !important;
  }
  .btns {
    justify-content: center;
  }
}
</style>
